import { getlist, addlist, updatelist, deletelist } from '@/api/classify'
export default {
    namespaced: true,
    state: {
        classify: [],
        form: {}
    },
    mutations: {
        SET_DATA(state, data) {
            let arr = [{}]
            arr = arr.concat(data)
            state.classify = arr
        },
        SET_FORM(state, form) {
            state.form = form
        }
    },
    actions: {
        async getlist({ commit }) {
            let r = await getlist()
            commit('SET_DATA', r.data)
        },
        async addlist({ dispatch }, form) {
            await addlist(form)
            dispatch('getlist')
        },
        async updatelist({ dispatch, state }) {
            await updatelist(state.form)
            dispatch('getlist')
        },
        async deletelist({ dispatch }, id) {
            let r = await deletelist(id)
            dispatch('getlist')
        }
    },
    modules: {
    }
}